package com.lizemin.inputoutput.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.IOException;

/**
 * @author lzm
 * @date 2025/4/4 16:12
 * @description
 */
@Slf4j
public class FixedResponseWrapper extends HttpServletResponseWrapper {

    public FixedResponseWrapper(HttpServletResponse response) {
        super(response);
    }

    // 这个方法被调用了两次，不明白为什么会这样
    @Override
    public ServletOutputStream getOutputStream() throws IOException {
        log.info("拿到response的输出流");
        ServletOutputStream outputStream = super.getOutputStream();
//        outputStream.print("hello world!\n");
        HttpServletResponse response = (HttpServletResponse) super.getResponse();
//        response.addHeader("X-Csrf-Token", "123456");
        return outputStream;
    }

}
